<?php
header("Content-Type: text/html; charset=utf-8");
include_once 'product.php';
include_once 'catalog.php';

$action=$_GET['action'];
if($action=="edit"){
	$product_info=new Product_info();
	$product_info->product_content=	$_POST['product_content'];
	$product_info->product_catlog_id=	$_POST['product_catlog_id'];
	$product_info->product_small_picture=	$_POST['product_small_picture'];
	$product_info->product_big_picture=	$_POST['product_big_picture'];
	$product_info->product_desc= $_POST['product_desc'];
	$product_info->product_name=$_POST['product_name'];
	$product_info->show_as_scroll=($_POST['show_as_scroll']=='on' ? 1: 0);
	$product_info->show_home_page=($_POST['show_home_page'] =='on' ? 1: 0);
	$product_info->product_add_time=date('Y-m-d H:i:s',time());
	$product_info->product_edit_time=date('Y-m-d H:i:s',time());
	$product_info->id=$_POST['id'];
	$ret=product_modify($product_info) ;

	if($ret!=true){
		echo "<script>alert('编辑失败！');</script>";
	}else{
		echo "<script>alert('编辑成功！');</script>";
	}
	echo ("<script>document.location='productList.php';</script>");
}else{
	$id=intval($_GET["id"]);
	$productList=list_product_by_id($id) ;
	if($productList!=false){
		$product=$productList[0];
	}
	$catListAll=list_catlog();
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>产品新增</title>
<link rel="stylesheet" type="text/css" href="../skin/css/base.css">
<link rel="stylesheet" href="../../editor/themes/default/default.css" />
<link rel="stylesheet" href="../../editor/plugins/code/prettify.css" />
<script charset="utf-8" src="../../editor/kindeditor.js"></script>
<script charset="utf-8" src="../../editor/lang/zh_CN.js"></script>
<script charset="utf-8" src="../../editor/plugins/code/prettify.js"></script>
<script>
		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="product_content"]', {
				cssPath : '../../editor/plugins/code/prettify.css',
				uploadJson : '../../editor/php/upload_json.php',
				fileManagerJson : '../../editor/php/file_manager_json.php',
				allowFileManager : true,
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						K('form[name=productForm]')[0].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						K('form[name=productForm]')[0].submit();
					});
				}
			});
			prettyPrint();
		});
	</script>
<style type="text/css">
.proItem {
	margin: 20px;
	padding-top: 5px;
}

.proItem .item {
	width: 780px;
	margin: 10px;
}

.proItem .item input {
	margin-left: 10px;
}

.proItem .item input.txtInput {
	width: 400px;
	margin-left: 10px;
}

.proItem .item select {
	width: 300px;
	margin-left: 10px;
}

.proItem .item textarea {
	width: 760px;
	height: 40px;
	float: left;
	margin-left: -25px;
}

.proItem .item input.btCenter {
	text-align: center;
	float: center;
}
</style>
</head>
<body leftmargin="8" topmargin="8" background='../skin/images/allbg.gif'>
<form action="productEdit.php?action=edit" method="post" name="productForm" id="productForm">
<div class="proItem">

<div class="item">产品名称:<input type="text" class="txtInput"	id="product_name" name="product_name"  value="<?=$product->product_name?>" /></div>
<div class="item">产品小图:<input type="text" class="txtInput"	id="product_small_picture" name="product_small_picture"  value="<?=$product->product_small_picture?>"/></div>
<div class="item">产品大图:<input type="text" class="txtInput"	id="product_big_picture" name="product_big_picture" value="<?=$product->product_big_picture?>" /></div>
<div class="item">显示在首页:<input type="checkbox" id="show_home_page"	name="show_home_page"  <?=$product->show_home_page==1 ? 'checked' :'' ?> /></div>
<div class="item">显示为滚动图片:<input type="checkbox" id="show_as_scroll"	name="show_as_scroll"  <?=$product->show_as_scroll==1 ? 'checked' :''?>  /></div>
<div class="item">产品分类:<select id="product_catlog_id"	name="product_catlog_id">
	<?php
	if($catListAll!=false){
		foreach ($catListAll  as $item) {
			$selected="";
			if($item->id==$product->product_catlog_id){
				$selected="selected='selected'";
			}
			?>
	<option   <?=$selected?>  value="<?=$item->id?>"><?=$item->catlog_name?></option>
	<?php
		}
	}
	?>
</select></div>
<div class="item">产品简介:<br />
<textarea id="product_desc" name="product_desc"><?=$product->product_desc?></textarea></div>
<div class="item">产品内容: 
<textarea name="product_content" id="product_content" style="width: 760px; height: 180px; visibility: hidden;"><?=$product->product_content?></textarea></div>
<div class="item"><input type="submit" value="提交" class="btCenter" /></div>
<input type="hidden" id='id'  name="id" value="<?=$_GET['id']?>" />
</div>
</form>
</body>
</html>
